package org.jeecg.modules.pipe.job;

import org.jeecg.common.config.TenantContext;
import org.jeecg.common.constant.TenantConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.SysTenantVo;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.device.entity.DevReservoirInfo;
import org.jeecg.modules.pipe.service.IMonitorPointService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Set;

/**
 * 示例带参定时任务
 * 
 * @Author Scott
 */
@Slf4j
public class PipeFlowLeakageJob implements Job {

	@Autowired
	private ISysBaseAPI baseAPI;
	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private IMonitorPointService monitorPointService;


	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

		//缓存获取租户ID列表
		Set<Object> tenantSet = redisUtil.sGet(TenantConstant.SYS_TENANT_CACHE_SET);
		if(null != tenantSet && tenantSet.size() > 0){
			for (Object tenantL : tenantSet) {
				TenantContext.setTenant(tenantL.toString());
				// 漏损
				monitorPointService.pipeLeakageAnalysis();
			}
		}

		log.info(" Job Execution key："+jobExecutionContext.getJobDetail().getKey());
		log.info(String.format(" 漏损定时任务 PipeFlowLeakageJob !  时间:" + DateUtils.getTimestamp()));
	}
}
